﻿using System;
using System.Linq;
using Pap.Data;
using Pap.Data.Abstraction.Utils;

namespace Pap.Services.Parent
{
    /// <summary>
    /// 
    /// </summary>
    public class ParentService : IParentService
    {
        /// <summary>
        /// 
        /// </summary>
        IDatabase _Database;
        /// <summary>
        /// Initializes a new instance of the <see cref="ParentService"/> class.
        /// </summary>
        /// <param name="database">The database.</param>
        public ParentService(IDatabase database)
        {
            _Database = database;
        }

        /// <summary>
        /// Gets the parent center.
        /// </summary>
        /// <param name="IssuePlaceID">The issue place ID.</param>
        /// <returns></returns>
        public ICenter GetParentCenter(Guid IssuePlaceID)
        {
            return (from Issueplace in _Database.IssuePlaces
                    where Issueplace.IssuePlaceID == IssuePlaceID
                    select Issueplace.CenterObj).FirstOrDefault();
        }

        /// <summary>
        /// Gets the parent governorate.
        /// </summary>
        /// <param name="CenterID">The center ID.</param>
        /// <returns></returns>
        public IGovernorate GetParentGovernorate(Guid CenterID)
        {
            return (from center in _Database.Centers
                    where center.CenterID == CenterID
                    select center.GovernorateObj).FirstOrDefault();
        }
    }
}
